package com.training.project.util;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.PrintWriter;

public class Seq {
	private static int num = 0;

	private static BufferedReader in;
	private static PrintWriter out;

	private static final String SEQ_PATH = "E:\\JavaWork\\java-io\\src\\com\\training\\project\\resources\\seq.dat";

	static {
		init();
	}
	
	private static void init() {
		try {
			in = new BufferedReader(new FileReader(SEQ_PATH));
			String line = in.readLine();
			num = Integer.parseInt(line);
			in.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static int nextVal() {
		try {
			out = new PrintWriter(SEQ_PATH);
			out.println(++num);
			out.close();
		} catch (FileNotFoundException e) {	
			e.printStackTrace();
		}
		return ++num;
	}
}
